using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public partial class FieldModel {
  //记录在一整次消除（从第一次消除到完全稳定）中的上下文信息
  public class MatchResolveContext {
    public struct BallSwap {
      public Vector2Int pos0;
      public Vector2Int pos1;
    }

    private List<BallSwap> m_cachedSwap = new List<BallSwap>();
    /* 消除的迭代数：
     * 在一整次消除中，每次棋盘稳定后产生的一次消除称为一次迭代
     * 区分迭代可以判断是首次消除还是连锁消除
     */
    private int m_generation;
    public int generation => m_generation;

    public int[] cachedReload {
      get; set;
    }

    public void OnMatch() {
      m_cachedSwap.Clear();
      m_generation++;
    }

    public void OnSettle() {
      m_cachedSwap.Clear();
      m_generation = 0;
    }

    public void CachePlayerSwap(Vector2Int pos0, Vector2Int pos1) {
      m_cachedSwap.Add(new BallSwap() {
        pos0 = pos0,
        pos1 = pos1
      });
    }

    public IEnumerable<BallSwap> PopCachedSwap() {
      var tmp = new List<BallSwap>(m_cachedSwap);
      m_cachedSwap.Clear();
      return tmp;
    }

  }
}

